import org.antlr.v4.Tool;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

public class AntlrTool {
    public static void main(String[] args) throws IOException {

     processLexer();
    //     processParser();


    }

    private static void processParser() {
        String g4 = "YJSParser.g4";
        String pkg;

        // g4 = "ExprParser.g4";
        if (g4.equals("YJSParser.g4"))
            pkg = "org.bdware.sc.parser";
        else
            pkg = "org.bdware.sc.parser.test";
        System.out.println("GenerateAt:" + "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"));
        File from = new File("./genparser/input/" + g4);

        File out = new File(g4);
        out.delete();
        try {
            Files.copy(from.toPath(), out.toPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
        // Tool.main(new String[] {});
        Tool.main(new String[]{g4, "-package", pkg, "-o", "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"});
        //	 Tool.main(new String[] { g5, "-package", pkg, "-o", "./gen/" +
        //	 pkg.replaceAll("\\.", "/"), "-visitor" });

        System.out.println("DeleteFiles!");
        out.delete();
    }

    private static void processLexer() {
        String g5 = "JavaScriptLexer.g4";
        String pkg = "org.bdware.sc.parser";

        File from = new File("./genparser/input/" + g5);
        File out = new File(g5);
        out.delete();
        try {
            Files.copy(from.toPath(), out.toPath());
            Tool.main(new String[]{g5, "-package", pkg, "-o", "./common/src/main/gen/" +
                    pkg.replaceAll("\\.", "/"), "-visitor"});
            new File(g5).delete();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
